import request from './request/index.js'

export async function getCategoriesTree() {
    try {
        const res = await request.get('/category/tree')
        return res.data
    } catch (err) {
        return Promise.reject(err)
    }
}

export async function addCategory(data) {
    try {
        const res = await request.post('/category', data)
        return res.data
    } catch (err) {
        return Promise.reject(err)
    }
}

export async function listCategories(data) {
    try {
        const res = await request.post('/category/list',data)
        return res.data
    } catch (err) {
        return Promise.reject(err)
    }
}

export async function updateCategory(data) {
    try {
        const res = await request.put('/category', data)
        return res.data
    } catch (err) {
        return Promise.reject(err)
    }
}

export async function deleteCategory(id) {
    try {
        const res = await request.delete(`/category/${id}`)
        return res.data
    } catch (err) {
        return Promise.reject(err)
    }
}